Skip to content

Conversation

@itzsudipta
Copy link

@itzsudipta itzsudipta commented Jan 17, 2026

Closes #
The PR is : #244

📝 Description

This PR adds robust error handling for the EMBEDDING_MAX_BATCH_SIZE environment variable. Previously, the application would encounter a ValueError and crash during startup if the environment variable was set to a non-integer string.

This change introduces a try-except block to ensure that if the environment variable is misconfigured, the system gracefully falls back to a default value of 32 and remains operational.

🔧 Changes Made

  • Enhanced Configuration Safety: Wrapped EMBEDDING_MAX_BATCH_SIZE parsing in a try-except block in backend/config.py.
  • Fallback Logic: Implemented a default value (32) to prevent application crashes on invalid input.
  • Improved Stability: Prevents deployment failures caused by simple environment configuration typos.

📷 Screenshots or Visual Changes (if applicable)

N/A: This is a backend logic change for stability.

🤝 Collaboration

✅ Checklist

  • I have read the contributing guidelines.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if applicable).
  • Any dependent changes have been merged and published in downstream modules.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for batch size configuration: invalid or non-integer values are now caught, a warning is logged, and a sensible default (32) is applied automatically.
    • More robust index setup on startup: index creation now has consolidated error handling and clearer logging, avoiding failures when indexes already exist.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

Adds guarded parsing for MAX_BATCH_SIZE in backend/config.py (defaults to 32 on invalid input, logs a warning) and centralizes graph index creation error handling in backend/.../api/graph.py by introducing _safe_create_index and replacing inline try/except blocks with calls to it.

Changes

Cohort / File(s) Summary
Configuration Error Handling
backend/config.py
Wraps the int(...) conversion for MAX_BATCH_SIZE in a try/except ValueError; logs a warning "Invalid integer for EMBEDDING_MAX_BATCH_SIZE. Defaulting to 32." and falls back to 32.
Graph Index Creation
backend/app/database/falkor/code-graph-backend/api/graph.py
Adds Graph._safe_create_index(self, func, label, *args) to centralize index creation error handling and logging; replaces inline index-creation try/except blocks with calls to _safe_create_index for the File range index and Searchable fulltext index.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibbled code with gentle paws,
Caught numbers drifting out of laws.
I wrapped the index in careful light,
Logged what’s wrong and made it right.
Thirty-two hops home through midnight jaws.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change of adding error handling for EMBEDDING_MAX_BATCH_SIZE parsing, which is the primary focus highlighted in the PR objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@backend/config.py`:
- Around line 15-19: The except handler for parsing EMBEDDING_MAX_BATCH_SIZE
references the logging module but logging is not imported, which will raise
NameError; fix by adding an import for the logging module at the top of the file
so the except block can call logging.warning without error (ensure logging is
imported before MAX_BATCH_SIZE is defined and used).

@itzsudipta
Copy link
Author

@smokeyScraper Hi there! I created issue #244 and have just uploaded my fix. I noticed a concurrent PR was opened, but I would ask you to consider my PR because it includes error-handling logic that prevents the server from failing to start due to configuration typos.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@backend/app/database/falkor/code-graph-backend/api/graph.py`:
- Around line 53-61: Replace the broad Exception handler in _safe_create_index
with redis.exceptions.ResponseError: import ResponseError from redis.exceptions,
change the except Exception as e block to except ResponseError as e, and keep
the existing "already exists" string check and logging behavior (logging.info
for existing index, logging.error with exc_info for other ResponseError cases)
so unrelated exceptions (connection/timeouts/auth) are no longer swallowed by
this method.

Comment on lines +53 to +61
def _safe_create_index(self, func, label, *args):
try:
self.g.create_node_range_index("File", "name", "ext")
except Exception:
pass
func(label, *args)
logging.debug(f"Successfully created/verified index for '{label}'.")
except Exception as e:
if "already exists" in str(e).lower():
logging.info(f"Index for '{label}' already exists.")
else:
logging.error(f"Failed to create index for '{label}': {e}", exc_info=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's find the full graph.py file to understand imports and context
find . -type f -name "graph.py" | grep -i falkor

Repository: AOSSIE-Org/Devr.AI

Length of output: 123


🏁 Script executed:

# Look for requirements files to identify FalkorDB version
find . -type f \( -name "requirements*.txt" -o -name "setup.py" -o -name "pyproject.toml" -o -name "Pipfile" \) | head -20

Repository: AOSSIE-Org/Devr.AI

Length of output: 235


🏁 Script executed:

# Search for FalkorDB imports in the codebase
rg "falkor|FalkorDB" -i --type py | head -30

Repository: AOSSIE-Org/Devr.AI

Length of output: 3693


🏁 Script executed:

# Check FalkorDB version in requirements
cat backend/app/database/falkor/code-graph-backend/requirements.txt

Repository: AOSSIE-Org/Devr.AI

Length of output: 8289


🏁 Script executed:

# Also check the main requirements
cat backend/requirements.txt | grep -i falkor

Repository: AOSSIE-Org/Devr.AI

Length of output: 44


🏁 Script executed:

# Read the full graph.py file to understand the context
wc -l backend/app/database/falkor/code-graph-backend/api/graph.py

Repository: AOSSIE-Org/Devr.AI

Length of output: 125


🏁 Script executed:

# Read the graph.py file
head -100 backend/app/database/falkor/code-graph-backend/api/graph.py

Repository: AOSSIE-Org/Devr.AI

Length of output: 3311


🏁 Script executed:

# Read lines around the _safe_create_index method (lines 53-61 plus surrounding context)
sed -n '1,100p' backend/app/database/falkor/code-graph-backend/api/graph.py

Repository: AOSSIE-Org/Devr.AI

Length of output: 3311


🏁 Script executed:

# Search for other exception handling patterns in the same file
rg "except" backend/app/database/falkor/code-graph-backend/api/graph.py -A 3

Repository: AOSSIE-Org/Devr.AI

Length of output: 391


🏁 Script executed:

# Look for other FalkorDB exception handling in the codebase
rg "except.*falkor" -i backend/app/database/falkor/code-graph-backend/ -A 2

Repository: AOSSIE-Org/Devr.AI

Length of output: 44


🌐 Web query:

FalkorDB 1.0.10 Python client exception types error handling

💡 Result:

In FalkorDB Python client v1.0.10, almost all runtime errors you’ll handle are redis-py exceptions, because the client is a thin wrapper around a redis.Redis(...) connection and ultimately calls execute_command(...) for FalkorDB commands. [1]

Exception types you should expect

1) FalkorDB-py custom exception

  • falkordb.exceptions.SchemaVersionMismatchException (the only documented custom exception type in the package). [2]

2) redis-py exceptions (primary ones to catch)
Catch from redis.exceptions (sync) / redis.asyncio (async), typically:

  • ResponseError: FalkorDB query/command errors (syntax errors, runtime errors like _AR_EXP_UpdateEntityIdx, etc.)
  • ConnectionError: can’t connect / connection dropped
  • TimeoutError: socket timeouts / blocked too long
  • AuthenticationError: bad credentials
  • (optional umbrella) RedisError: base class for most redis-py client exceptions

Practical error-handling pattern

from redis.exceptions import ResponseError, ConnectionError, TimeoutError, AuthenticationError, RedisError
from falkordb.exceptions import SchemaVersionMismatchException

try:
    res = g.query("MATCH (n) RETURN n LIMIT 1")
except ResponseError as e:
    # FalkorDB reported an error executing the command/query
    msg = str(e)
    # inspect msg for FalkorDB error codes/messages if you need branching
    raise
except (ConnectionError, TimeoutError, AuthenticationError) as e:
    # transport / auth problems
    raise
except SchemaVersionMismatchException as e:
    # schema cache/version mismatch (raised by the client’s schema machinery)
    raise
except RedisError as e:
    # any other redis-py error
    raise

Notes:

  • If you’re specifically seeing FalkorDB engine errors while running queries (common in FalkorDB==1.0.10 reports), they will surface as redis.exceptions.ResponseError because the server returns an error reply. [1]
  • v1.0.10 itself is a “version bump” release (plus connection-related tweaks like TLS support via from_url), not an exceptions redesign—so the above model is what you should rely on. [3]

Sources:
[1] FalkorDB client builds on redis.Redis and exposes execute_command (readthedocs module source). (falkordb-py.readthedocs.io)
[2] SchemaVersionMismatchException definition (readthedocs exceptions module). (falkordb-py.readthedocs.io)
[3] v1.0.10 release notes / what changed. (github.com)

Citations:


Catch redis.exceptions.ResponseError instead of broad Exception.

FalkorDB v1.0.10 is a thin wrapper around redis-py, so "index already exists" errors surface as redis.exceptions.ResponseError, not a FalkorDB-specific exception type. Catching Exception masks unrelated errors (connection failures, timeouts, authentication errors) that deserve different handling.

While string-based matching for "already exists" is not ideal, it remains the only viable approach since there's no specific error code exposed. However, catching ResponseError provides better specificity:

from redis.exceptions import ResponseError

def _safe_create_index(self, func, label, *args):
    try:
        func(label, *args)
        logging.debug(f"Successfully created/verified index for '{label}'.")
    except ResponseError as e:
        if "already exists" in str(e).lower():
            logging.info(f"Index for '{label}' already exists.")
        else:
            logging.error(f"Failed to create index for '{label}': {e}", exc_info=True)
🤖 Prompt for AI Agents
In `@backend/app/database/falkor/code-graph-backend/api/graph.py` around lines 53
- 61, Replace the broad Exception handler in _safe_create_index with
redis.exceptions.ResponseError: import ResponseError from redis.exceptions,
change the except Exception as e block to except ResponseError as e, and keep
the existing "already exists" string check and logging behavior (logging.info
for existing index, logging.error with exc_info for other ResponseError cases)
so unrelated exceptions (connection/timeouts/auth) are no longer swallowed by
this method.

@itzsudipta itzsudipta closed this Feb 3, 2026
@itzsudipta itzsudipta deleted the contribute-sudipta branch February 3, 2026 15:16
@itzsudipta itzsudipta restored the contribute-sudipta branch February 3, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant